package com.ruoyi.templateFile.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.templateFile.domain.TemplateFile;
import com.ruoyi.templateFile.service.ITemplateFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品模板Controller
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/templateFile/templateFile")
public class TemplateFileController extends BaseController
{
    @Autowired
    private ITemplateFileService templateFileService;

    /**
     * 查询产品模板列表
     */
    @PreAuthorize("@ss.hasPermi('templateFile:templateFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemplateFile templateFile)
    {
        startPage();
        List<TemplateFile> list = templateFileService.selectTemplateFileList(templateFile);
        return getDataTable(list);
    }

    /**
     * 导出产品模板列表
     */
    @PreAuthorize("@ss.hasPermi('templateFile:templateFile:export')")
    @Log(title = "产品模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TemplateFile templateFile)
    {
        List<TemplateFile> list = templateFileService.selectTemplateFileList(templateFile);
        ExcelUtil<TemplateFile> util = new ExcelUtil<TemplateFile>(TemplateFile.class);
        util.exportExcel(response, list, "产品模板数据");
    }

    /**
     * 获取产品模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('templateFile:templateFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(templateFileService.selectTemplateFileById(id));
    }

    /**
     * 新增产品模板
     */
    @PreAuthorize("@ss.hasPermi('templateFile:templateFile:add')")
    @Log(title = "产品模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TemplateFile templateFile)
    {
        return toAjax(templateFileService.insertTemplateFile(templateFile));
    }

    /**
     * 修改产品模板
     */
    @PreAuthorize("@ss.hasPermi('templateFile:templateFile:edit')")
    @Log(title = "产品模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemplateFile templateFile)
    {
        return toAjax(templateFileService.updateTemplateFile(templateFile));
    }

    /**
     * 删除产品模板
     */
    @PreAuthorize("@ss.hasPermi('templateFile:templateFile:remove')")
    @Log(title = "产品模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(templateFileService.deleteTemplateFileByIds(ids));
    }
}
